package com.todo.strategy.online.application.convert;

import com.todo.common.common.enums.EnableTypeEnum;
import com.todo.common.utils.TodoCommonUtils;
import com.todo.strategy.common.enums.MemoSuggestStrategyEnum;
import com.todo.strategy.common.enums.MemoTypeEnum;
import com.todo.strategy.online.application.entity.bo.MemoTemplateBO;
import com.todo.strategy.online.application.entity.bo.MemoUserRelationBO;
import com.todo.strategy.online.infrastructure.entity.domain.MemoTemplateDO;
import com.todo.strategy.online.infrastructure.entity.domain.MemoUserRelationDO;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author azhebuxing
 * @date 2024/11/28 03:10
 * @description
 */
public class MemoTemplateConvert {
    public static MemoTemplateDO convertToMemoTemplateContentDO(MemoTemplateBO memoTemplateBO) {
        if (memoTemplateBO == null){
            return null;
        }
        MemoTemplateDO memoTemplateDO = new MemoTemplateDO();
        memoTemplateDO.setIsPlatform(memoTemplateBO.getIsPlatform());
        memoTemplateDO.setBaseType(memoTemplateBO.getMemoTypeEnum() == null ? null : memoTemplateBO.getMemoTypeEnum().getType());
        memoTemplateDO.setName(memoTemplateBO.getName());
        memoTemplateDO.setDesc(memoTemplateBO.getDesc());
        memoTemplateDO.setReferenceOpinion(memoTemplateBO.getReferenceOpinion());
        memoTemplateDO.setSuggestStrategy(memoTemplateBO.getSuggestStrategy() == null ? null : memoTemplateBO.getSuggestStrategy().getType());
        memoTemplateDO.setContentModel(memoTemplateBO.getContentModel());
        memoTemplateDO.setUserId(memoTemplateBO.getUserId());
        memoTemplateDO.setStatus(memoTemplateBO.getStatus() == null ? null : memoTemplateBO.getStatus().getType());
        memoTemplateDO.setUseCount(memoTemplateBO.getUseCount());
        memoTemplateDO.setId(memoTemplateBO.getId() == null ? TodoCommonUtils.buildLongGuid() : memoTemplateBO.getId());
        memoTemplateDO.setIsDelete(memoTemplateBO.getIsDelete());
        memoTemplateDO.setCreateTime(memoTemplateBO.getCreateTime());
        memoTemplateDO.setUpdateTime(memoTemplateBO.getUpdateTime());
        return memoTemplateDO;
    }

    public static MemoTemplateBO convertToMemoTemplateBO(MemoTemplateDO memoTemplateDO) {
        if (memoTemplateDO == null) {
            return null;
        }
        MemoTemplateBO memoTemplateBO = new MemoTemplateBO();
        memoTemplateBO.setIsPlatform(memoTemplateDO.getIsPlatform());
        memoTemplateBO.setMemoTypeEnum(MemoTypeEnum.getByType(memoTemplateDO.getBaseType()));
        memoTemplateBO.setName(memoTemplateDO.getName());
        memoTemplateBO.setDesc(memoTemplateDO.getDesc());
        memoTemplateBO.setReferenceOpinion(memoTemplateDO.getReferenceOpinion());
        memoTemplateBO.setSuggestStrategy(MemoSuggestStrategyEnum.getByType(memoTemplateDO.getSuggestStrategy()));
        memoTemplateBO.setContentModel(memoTemplateDO.getContentModel());
        memoTemplateBO.setUserId(memoTemplateDO.getUserId());
        memoTemplateBO.setStatus(EnableTypeEnum.getByType(memoTemplateDO.getStatus()));
        memoTemplateBO.setUseCount(memoTemplateDO.getUseCount());
        memoTemplateBO.setId(memoTemplateDO.getId());
        memoTemplateBO.setIsDelete(memoTemplateDO.getIsDelete());
        memoTemplateBO.setCreateTime(memoTemplateDO.getCreateTime());
        memoTemplateBO.setUpdateTime(memoTemplateDO.getUpdateTime());
        return memoTemplateBO;
    }

    public static List<MemoTemplateBO> convertTomemoTemplateDOList(List<MemoTemplateDO> memoTemplateDOList) {
        if (CollectionUtils.isEmpty(memoTemplateDOList)){
            return Collections.emptyList();
        }
        return memoTemplateDOList.stream().map(MemoTemplateConvert::convertToMemoTemplateBO).collect(Collectors.toList());
    }

    public static MemoUserRelationDO convertToMemoUserRelationDO(MemoUserRelationBO memoUserRelationBO) {
        if (memoUserRelationBO == null){
            return null;
        }
        MemoUserRelationDO memoUserRelationDO = new MemoUserRelationDO();
        memoUserRelationDO.setIsFinish(memoUserRelationBO.getIsFinish());
        memoUserRelationDO.setRemark(memoUserRelationBO.getRemark());
        memoUserRelationDO.setPlanId(memoUserRelationBO.getPlanId());
        memoUserRelationDO.setUserId(memoUserRelationBO.getUserId());
        memoUserRelationDO.setContent(memoUserRelationBO.getContent());
        memoUserRelationDO.setIsDelete(memoUserRelationBO.getIsDelete());
        memoUserRelationDO.setId(memoUserRelationBO.getId());
        memoUserRelationDO.setCreateTime(memoUserRelationBO.getCreateTime());
        memoUserRelationDO.setUpdateTime(memoUserRelationBO.getUpdateTime());
        return memoUserRelationDO;
    }

    public static MemoUserRelationBO convertToMemoUserRelationBO(MemoUserRelationDO memoUserRelationDO) {
        if (memoUserRelationDO == null) {
            return null;
        }
        MemoUserRelationBO memoUserRelationBO = new MemoUserRelationBO();
        memoUserRelationBO.setIsFinish(memoUserRelationDO.getIsFinish());
        memoUserRelationBO.setRemark(memoUserRelationDO.getRemark());
        memoUserRelationBO.setPlanId(memoUserRelationDO.getPlanId());
        memoUserRelationBO.setUserId(memoUserRelationDO.getUserId());
        memoUserRelationBO.setContent(memoUserRelationDO.getContent());
        memoUserRelationBO.setIsDelete(memoUserRelationDO.getIsDelete());
        memoUserRelationBO.setId(memoUserRelationDO.getId());
        memoUserRelationBO.setCreateTime(memoUserRelationDO.getCreateTime());
        memoUserRelationBO.setUpdateTime(memoUserRelationDO.getUpdateTime());
        return memoUserRelationBO;
    }
}

